#!/bin/bash

set -euxo pipefail

llvm=true

while [[ $# -gt 0 ]]; do
  case "$1" in
    --frontend)
      llvm=false
      shift
      ;;
  esac
done

mkdir -p $DESTDIR$PREFIX/bin
mkdir -p $DESTDIR$PREFIX/include
mkdir -p $DESTDIR$PREFIX/lib
mkdir -p $DESTDIR$PREFIX/share
cp -R k-distribution/target/release/k/bin/* $DESTDIR$PREFIX/bin
cp -R k-distribution/target/release/k/include/* $DESTDIR$PREFIX/include
cp -R k-distribution/target/release/k/lib/* $DESTDIR$PREFIX/lib
cp -R k-distribution/target/release/k/share/* $DESTDIR$PREFIX/share

if [ "$llvm" = "true" ]; then
  ( cd llvm-backend/target/build && make install )
fi
